<template>
  <div>
    <el-form :model="dynamicValidateForm" ref="dynamicValidateForm" label-width="100px" class="demo-dynamic">
      <div style="margin:20px 0;">
        <span style="font-size:35px;font-weight:600;">公司简介</span>
      </div>
      <div style="margin:10px 0;">
        <span style="font-size:25px;color:red;">(上下拖动简介、段落文本框右下角改变高度)</span>
      </div>
      <div style="margin:10px 0;">
        <span style="font-size:25px;color:red;">(段落换行直接回车换行即可，不需要考虑每段前空两个字符)</span>
      </div>
      <el-form-item prop="title" label="标题">
        <el-input style="font-size:18px;" v-model="dynamicValidateForm.title"></el-input>
      </el-form-item>
      <el-form-item label="内容" :prop="dynamicValidateForm.content">
        <el-input :autosize="{ minRows: 10}" style="font-size:18px;" type="textarea"
          v-model="dynamicValidateForm.content"></el-input>
      </el-form-item>
      <div style="margin:15px 0;">
        <el-button type="primary" @click="submitForm()">提交</el-button>
      </div>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'Lunch',
  data () {
    return {
      dynamicValidateForm: {
        title: '',
        introduction: '',
        content: ''
      },
      Form: {
        title: '',
        introduction: '',
        content: ''
      },
      imgList: []
    }
  },
  methods: {
    submitForm (formName) {
      if (this.dynamicValidateForm.title && this.dynamicValidateForm.content) {
        this.Form = this.dynamicValidateForm
        var text = this.dynamicValidateForm.content
        var re = /\n/g
        var string = text.replace(re, '<span>')
        this.Form.content = string
        this.$axios({
          method: 'put',
          url: '/introduction/update',
          data: {
            id: 3,
            title: this.Form.title,
            content: this.Form.content
          }
        }).then((res) => {
          if (res.data.message === 'SUCCESS') {
            this.getData()
            this.open('修改成功！')
          }
        })
      }
    },
    open (text) {
      this.$notify({
        title: '成功',
        message: text,
        type: 'success'
      })
    },
    getData () {
      this.$axios({
        method: 'get',
        url: '/introduction/get'
      }).then((res) => {
        var data = res.data.data
        var string = res.data.data.content
        var re = /<span>/g
        var str = string.replace(re, '\n')
        data.content = str
        this.dynamicValidateForm = data
      })
    }
  },
  mounted () {
    this.getData()
  }
}
</script>

<style scoped>
.imgItem {
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
  overflow: hidden;
  margin: 15px 0;
}
.img {
  width: 450px;
  height: 300px;
}
.ipt {
  width: 350px;
}
</style>
